package com.googlecode.lookie.platform.laf;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.richclient.settings.Settings;

import com.googlecode.lookie.platform.settings.LookieSettingsManager;
import com.googlecode.lookie.swing.laf.AbstractLookAndFeelConfigurer;
import com.googlecode.lookie.swing.laf.LookAndFeelDescriptor;
import com.googlecode.lookie.swing.laf.LookAndFeelRegistry;

public class LookieLookAndFeelConfigurer
    extends AbstractLookAndFeelConfigurer
    implements InitializingBean
{

    @Autowired
    private LookAndFeelRegistry lookAndFeelRegistry;

    @Autowired
    private LookieSettingsManager settingsManager;

    public void afterPropertiesSet()
        throws Exception
    {
        Settings userSettings = settingsManager.getUserSettings();

        LookAndFeelDescriptor descriptor = LookAndFeelRegistryHelper.getPreferredDescriptor( lookAndFeelRegistry,
                                                                                             userSettings );

        // descriptor is null if regular and/or default preference for look and
        // feel does not match any of the known (registered) descriptors

        configure( descriptor );
    }

}
